package com.daxt.controller.filemanager;

import cn.hutool.core.util.ZipUtil;
import com.daxt.base.common.util.RedisUtil;
import com.daxt.common.annotations.OperLog;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.sys.ArchivesTypeMapper;
import com.daxt.service.MountService;
import com.daxt.utils.file.FileBaseUtil;
import com.daxt.utils.file.JDomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.List;

@Api(tags = "打包")
@RestController
@RequestMapping("/pack")
public class PackController {

	@Autowired
	private ArchivesTypeMapper archivesTypeMapper;

//	@Value(value = "${systemConfig.tempPath}")
//	private String basePath1;
	@Autowired
	private MountService mountService;
	@Autowired
	private RedisUtil redisUtil;
	

	@ApiOperation(value = "创建pack文件", notes = "")
	@PostMapping("/create")
	@OperLog(operModul = "打包文件", operType = "ADD", operDesc = "新日志")
	public Result<String> pack(@RequestBody List<String> ids) {

		String packPath = "d:/a/pack";
		FileBaseUtil.mkdir(packPath);

		String content = "说明文件内容";
		//创建《说明文件.txt》文件
		FileBaseUtil.writeTxt(content,packPath + "/说明文件.txt",false);

		//创建《目录文件.xml》
        JDomUtil.createJDOM(new File(packPath + "/目录文件.xml"));
		//创建文件夹《电子档案》  - 《子件1》、《子件2》 - 发文处理笺及日志、附件...、关于XXX的通知（带图章）.pdf、关于XXX的通知（加盖电子印章）.pdf、正文内容doc、电子档案1.xml
		FileBaseUtil.mkdir(packPath + "/电子档案");
		FileBaseUtil.mkdir(packPath + "/电子档案" + "/子件1");
		FileBaseUtil.mkdir(packPath + "/电子档案" + "/子件2");
		//创建《归档信息表.xml》
		JDomUtil.createJDOM(new File(packPath + "/归档信息表.xml"));

		ZipUtil.zip(packPath, packPath + ".zip");




		
		return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), "参数异常", null);
	}

}
